home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS08.ADF
/
Text
/
FixLatticeMain
< prev
next >
Wrap
Text File
|
1986-04-02
|
3KB
|
69 lines
Lattice C V3.02 does not provide full Unix compatability on its command
line parser. Most of the time that's OK, but there are two situations
where that's not good enough. first, any program that wants to be able to
handle as an argument any valid Amiga filename will not work
(i.e. "TEST FILE"), because blanks are seen as delimiters, the file name
will be broken into two arguments: '"TEST', and 'PARM"'. Secondly, certain
arguments to GREP which would require the pattern string to be in quotes
will not work for the same reason. I mentioned this to Lattice, but they
didn't see fit to comment on it, so I don't know if V3.03 or later fixes the
problem. Fortunately, you can do this yourself. Included in the 'examples'
directory on the distribution disk is the module "_main". The first thing
you need to do is remove the binary trash that's in the file so that ED
can edit it.
The Lattice version has a simple solution to parsing the
command line: it skips over spaces, fills the argument array with pointers
to the first non-space character of each argument, and then jams a NULL
where the trailing space or null is. The way that they did it is tacky and
in my mind dangerous - they modify the parm string owned by the
AmigaDos CLI. I recommend that you 'strcpy' the parm into a local string
(128 bytes should be adequate) and mutilate IT, instead. That way, should
Commodore-Amiga decide to look at its parm string after the program has
been called in some future release (don't ask me why) or store it in
protected memory, etc., you won't experience mysterious program and/or system
failures.
Anyway, to handle the quoted parameter problem - I'm not sure about Unix,
but my CP/M system accepted both single and double quotes as delimiters, so
that's the way I set it up here:
#define NULL '\0'
#define SINGLE_QUOTE '\''
#define DOUBLE_QUOTE '\"'
/*---- replace main program's for loop innards with the following... */
{
while (isspace(*line)) line++; /* skip leading spaces */
if (*line == NULL) break;
if ((*line == SINGLE_QUOTE) || (*line == DOUBLE_QUOTE))
quote_it (*line);
else
{
argv[argc++] = line; /* pointer to parm */
while (!isspace(*line) && (*line != NULL)) line++; /* scan characters */
}
... leave rest of Lattice stuff as is ....
}
void
quote_it (delimiter) /* handle quotes - define as void prior to above */
char * delimiter;
{
argv[argc++] = ++line; /* point to text of string */
while ((*line != delimiter) && (*line != NULL)) line++;
/* now let main program jam null over closing delimiter */
}
You may notice that this code doesn't give a hang about screwed up or
missing final quotes. You can insert error messages if you like, just
remember that the TINY option if selected will remove access to stdout and
stderr - by definition.
I haven't tried this out myself yet, but it should be substantially correct.
If it isn't let me (and the rest of us!) know. Your updated _main goes (I
think!) into the C 'lib' directory as 'Lstartup.obj'. Good Luck!
Tim Holloway [73026,2026]